<include file='Common:header' />
<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">
	<!-- #section:basics/sidebar -->
	<include file='Common:left' />
	<!-- /section:basics/sidebar -->
	<div class="main-content">
		<div class="main-content-inner">
			<div class="page-content">


				<div class="row">
					<div class="col-xs-12">
						<div>
						<form id="alldel" name="alldel" method="post" action="{:U('comment_alldel')}" >
							<input name="p" id="p" value="{:I('p',1)}" type="hidden" />
							<div class="table-responsive">
							<table class="table table-striped table-bordered table-hover" id="dynamic-table">
								<thead>
								<tr>
									<th class="hidden-xs center">
										<label class="pos-rel">
											<input type="checkbox" class="ace"  id='chkAll' onclick='CheckAll(this.form)' value="全选"/>
											<span class="lbl"></span>
										</label>
									</th>
									<th>ID</th>
									<th>评论人</th>
									<th class="hidden-sm hidden-xs">评论人邮箱</th>
									<th>评论内容</th>
									<th class="hidden-xs">审核</th>
									<th class="hidden-sm hidden-xs">留言时间</th>
									<th style="border-right:#CCC solid 1px;">操作</th>
								</tr>
								</thead>

								<tbody>

								<foreach name="comments" item="v">
									<tr>
										<td class="hidden-xs" align="center">
											<label class="pos-rel">
												<input name='c_id[]' id="navid" class="ace"  type='checkbox' value='{$v.c_id}'>
												<span class="lbl"></span>
											</label>
										</td>
										<td>{$v.c_id}</td>
										<td height="28">{$v.full_name}</td>
										<td class="hidden-sm hidden-xs">{$v.email}</td>
										<td>{$v.c_content}</td>
										<td class="hidden-xs">
											<if condition="$v['c_status'] eq 1">
												<a class="red" href="javascript:;" onclick="return stateyes({$v.c_id});" title="已审">
													<div id="zt{$v.c_id}"><button class="btn btn-minier btn-yellow">已审</button></div>
												</a>
												<else/>
												<a class="red" href="javascript:;" onclick="return stateyes({$v.c_id});" title="未审">
													<div id="zt{$v.c_id}"><button class="btn btn-minier btn-danger">未审</button></div>
												</a>
											</if>
										</td>
										<td class="hidden-sm hidden-xs">{$v.createtime|date='Y-m-d H:i:s',###}</td>
										<td>
											<div class="action-buttons">
												<a class="red del" href="{:U('comment_del',array('c_id'=>$v['c_id'],'p'=>I('p',1)))}" title="删除">
												<i class="ace-icon fa fa-trash-o bigger-130"></i>
												</a>
											</div>
										</td>
									</tr>
								</foreach>
								<tr>
									<td align="left"><button id="btnsubmit" class="btn btn-white btn-yellow btn-sm">删</button> </td>
									<td colspan="8" align="right" class="hidden-xs">{$page}</td>
									<td colspan="8" align="right" class="hidden-lg hidden-md hidden-sm">{$page_min}</td>
								</tr>
								</tbody>
							</table>
							</div>
						</form>	
						</div>
					</div>
				</div>

				<include file='Common:header_nav' />

			</div><!-- /.page-content -->
		</div>
	</div><!-- /.main-content -->

	<script>
		$(function(){
			//删除操作
			var $del = $(".del");
			$del.click(function(){
				var $url=this.href;
				layer.confirm('你确定要删除吗？包括其下子评论', {icon: 3}, function(index){
				layer.close(index);
				$.get($url, function(data){
					if(data.status){
						layer.alert(data.info, {icon: 6}, function(index){
							layer.close(index);
							window.location.href=data.url;
						});
					} else {
						layer.alert(data.info, {icon: 5}, function(index){
							layer.close(index);
						});
					}
				}, "json");
				});
				return false;
			});
		});
		//状态变更
		function stateyes(val){
			$.post('{:U("comment_state")}',
					{x:val},
					function(data){
						var $v=val;
						if(data.status){
							if(data.info=='未审'){
								var a='<button class="btn btn-minier btn-danger">未审</button>'
								$('#zt'+val).html(a);
								return false;
							}else{
								var b='<button class="btn btn-minier btn-yellow">已审</button>'
								$('#zt'+val).html(b);
								return false;
							}

						}else{
							layer.alert(data.info, {icon: 5});
						}
					});
			return false;
		}
		//多选
		function unselectall(){
			if(document.myform.chkAll.checked){
				document.myform.chkAll.checked = document.myform.chkAll.checked&0;
			}
		}
		function CheckAll(form){
			for (var i=0;i<form.elements.length;i++){
				var e = form.elements[i];
				if (e.Name != 'chkAll'&&e.disabled==false)
					e.checked = form.chkAll.checked;
			}
		}
		$(function(){
			$('#alldel').ajaxForm({
				beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置，一般是判断为空获取其他规则
				success: complete, // 这是提交后的方法
				dataType: 'json'
			});

			function checkForm(){
				var chk_value =[];
				$('input[id="navid"]:checked').each(function(){
					chk_value.push($(this).val());
				});

				if(!chk_value.length){
					layer.alert('至少选择一个删除项', {icon: 5});
					return false;
				}
			}

			function complete(data){
				if(data.status==1){
					layer.alert(data.info, {icon: 6}, function(index){
						layer.close(index);
						window.location.href=data.url;
					});
				}else{
					layer.alert(data.info, {icon: 5}, function(index){
						layer.close(index);
					});
				}
			}
		});

	</script>
	<include file='Common:footer' />

</div><!-- /.main-container -->
</body>
</html>
